package org.pinda.gui;

import org.johnnei.engine.GameMouse;
import org.lwjgl.input.Keyboard;

/**
 * The GUI Controller<br/>
 * In here all mouse clicks and keyboard strokes will be managed and parsed through the GUI structure
 * @author Johnnei
 *
 */
public class GuiController extends Gui {

	public GuiController(int width, int height) {
		super(null, 0, 0, 0, width, height);
	}
	
	@Override
	public void onTick(int deltaMs) {
		super.onTick(deltaMs);
		//Mouse - Left
		if(GameMouse.getInstance().isButtonDown(GameMouse.LEFT_BUTTON)) {
			onClick(GameMouse.LEFT_BUTTON, GameMouse.getInstance().getX(), GameMouse.getInstance().getY());
		}
		//Mouse - Right
		if(GameMouse.getInstance().isButtonDown(GameMouse.RIGHT_BUTTON)) {
			onClick(GameMouse.RIGHT_BUTTON, GameMouse.getInstance().getX(), GameMouse.getInstance().getY());
		}
		//Keyboard
		while(Keyboard.next()) {
			if(Keyboard.getEventKeyState()) {
				char key = Keyboard.getEventCharacter();
				if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
					if(key >= 97 && key <= 122)
						key -= 32; //To Uppercase
				}
				onKeyPress(key);
			}
		}
	}

}
